package com.ys.tdm.interceptor;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.ys.tdm.bean.user.User;
import com.ys.tdm.service.user.IUserService;

/**
 * 登录拦截
 * 
 * @Title:
 * @Description:TODO
 * @author Troy
 * @date 2017年12月25日 上午10:29:52
 * @version V1.0
 * @Copyright:Copyright (c) 亚厦股份2016 ~ 2017 版权所有
 */
public class LoginInteceptor extends HandlerInterceptorAdapter {
	private Logger logger = Logger.getLogger(LoginInteceptor.class);
	
	@Resource
	private IUserService userService;
	
	
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		/* Cookie[] cookies = request.getCookies();//这样便可以获取一个cookie数组  
		 User user = new User();
         if(null==cookies) {  
             System.out.println("没有cookie=========");  
         }else{  
             for(Cookie cookie : cookies){  
            	 if (cookie.getName().equals("USER_ID")) {
            		 User user2 = new User();
            		 user.setId(cookie.getValue());
            		 List<User> allUser = userService.getAll(user2);
            		 if (!allUser.isEmpty()) {
            			 user = allUser.get(0);
            			 
         			}
				} 
             }  
         }*/
			return true;

	}

	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
			ModelAndView modelAndView) throws Exception {
	}

}
